/*
 * Copyright @ 2024 weili23
 * com.sky.controller.admin 10:58
 * All right reserved.
 */

package com.sky.controller.admin;

import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.service.UserService;
import com.sky.vo.OrderReportVO;
import com.sky.vo.SalesTop10ReportVO;
import com.sky.vo.TurnoverReportVO;
import com.sky.vo.UserReportVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDate;

/**
 * @desc:统计模块
 * @author: weili23
 * @createTime: 2024/11/14 10:58
 * @version: v1.0
 */
@Api(tags = "统计接口")
@RestController
@RequestMapping("/admin/report")
@Slf4j
public class ReportService {
    @Resource
    private OrderService orderService;
    @Resource
    private UserService userService;
    @GetMapping("/turnoverStatistics")
    @ApiOperation("营业额统计")
    public Result<TurnoverReportVO> getTurnOverStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        TurnoverReportVO vo =orderService.getTurnOverStatistics(begin,end);
        return Result.success(vo);
    }

    @ApiOperation("用户统计")
    @GetMapping("/userStatistics")
    public Result<UserReportVO>  getUserStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        UserReportVO vo = userService.getUserStatistics(begin,end);
        return Result.success(vo);

    }

    @ApiOperation("订单统计")
    @GetMapping("/ordersStatistics")
    public Result<OrderReportVO>  getOrdersStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        OrderReportVO vo = orderService.getOrdersStatistics(begin,end);
        return Result.success(vo);

    }

    @ApiOperation("统计销量排名top10")
    @GetMapping("/top10")
    public Result<SalesTop10ReportVO>  getTop10(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        SalesTop10ReportVO vo = orderService.getTop10(begin,end);
        return Result.success(vo);

    }
}
